package com.starbugs.wehcat.controller;

import com.starbugs.wehcat.pojo.User;
import com.starbugs.wehcat.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
public class UserController {

  @Autowired
  private UserService userService;

  //搜索用户  /findUser?name=test

  @GetMapping("/findUser")
  public List<User> findUser(@RequestParam(value = "name") String name){
    System.out.println("name="+name);
    User user = new User();
    user.setName(name);
    log.info(user + "");
    Example<User> example =Example.of(user);
    return userService.getAll(example);
  }

  //保存用户

  @PostMapping("/saveUser")
  public String saveUser(@RequestBody User user){
    userService.saveUser(user);
    return "保存成功！";
  }
}
